﻿using System;
using PhiStore.Packages;
using PhiStore.Threading;

namespace PhiStore.Communication
{
    internal class PeerContainer : IEquatable<PeerContainer>
    {
        private BroadcastObject bc;
        public BroadcastObject BC
        {
            get
            {
                return bc;
            }
            set
            {
                lock (bc)
                {
                    bc = value;
                }
            }
        }

        public Channel<ForwardedPackage> PeerWorkerChannel;
        public PeerContainer(BroadcastObject bc, Channel<ForwardedPackage> channel)
        {
            this.bc = bc;
            this.PeerWorkerChannel = channel;
        }

        public bool IsAlive
        {
            get { return !PeerWorkerChannel.IsPoisoned; }
        }

        public override string ToString()
        {
            return BC.ToString();
        }

        public override bool Equals(object obj)
        {
            return BC.Equals(obj);
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public bool Equals(PeerContainer other)
        {
            return BC.Equals(other.BC);
        }
    }
}
